﻿// <copyright file="Address.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-10-09</date>
// <summary>OpenSocial address</summary>

namespace opensocial
{
    using System.Globalization;
    using System.Windows.Browser;
    using Synergist;

    /// <summary>
    /// OpenSocial address
    /// </summary>
    public class Address
    {
        /// <summary>
        /// Prefix for all fields
        /// </summary>
        private const string Prefix = "opensocial.Address.Field.";

        /// <summary>
        /// Initializes a new instance of the Address class.
        /// </summary>
        /// <param name="baseObject">The JavaScript opensocial.Address object</param>
        public Address(ScriptObject baseObject)
        {
            if (baseObject == null)
            {
                return;
            }

            this.Country = baseObject.getField(Prefix + "COUNTRY") as string;
            this.ExtendedAddress = baseObject.getField(Prefix + "EXTENDED_ADDRESS") as string;
            this.Latitude = baseObject.getField(Prefix + "LATITUDE") as string;
            this.Longitude = baseObject.getField(Prefix + "LONGITUDE") as string;
            this.POBox = baseObject.getField(Prefix + "PO_BOX") as string;
            this.PostalCode = baseObject.getField(Prefix + "POSTAL_CODE") as string;
            this.Region = baseObject.getField(Prefix + "REGION") as string;
            this.StreetAddress = baseObject.getField(Prefix + "STREET_ADDRESS") as string;
            this.AddressType = baseObject.getField(Prefix + "TYPE") as string;
            this.UnstucturedAddress = baseObject.getField(Prefix + "UNSTRUCTURED_ADDRESS") as string;
        }

        #region Properties
        /// <summary>
        /// Gets or sets the country
        /// </summary>
        public string Country { get; set; }

        /// <summary>
        /// Gets or sets the extended address
        /// </summary>
        public string ExtendedAddress { get; set; }

        /// <summary>
        /// Gets or sets the latitude
        /// </summary>
        public string Latitude { get; set; }

        /// <summary>
        /// Gets or sets the locality
        /// </summary>
        public string Locality { get; set; }

        /// <summary>
        /// Gets or sets the longitude
        /// </summary>
        public string Longitude { get; set; }

        /// <summary>
        /// Gets or sets the PO Box
        /// </summary>
        public string POBox { get; set; }

        /// <summary>
        /// Gets or sets the postal code
        /// </summary>
        public string PostalCode { get; set; }

        /// <summary>
        /// Gets or sets the region
        /// </summary>
        public string Region { get; set; }

        /// <summary>
        /// Gets or sets the street address
        /// </summary>
        public string StreetAddress { get; set; }

        /// <summary>
        /// Gets or sets the address type
        /// </summary>
        public string AddressType { get; set; }

        /// <summary>
        /// Gets or sets the unstructured address
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unstuctured", Justification = "Mirroring OpenSocial API.")]
        public string UnstucturedAddress { get; set; }

        #endregion
    
        /// <summary>
        /// Gets the properties for the object
        /// </summary>
        /// <returns>a string listing the non-null properties and their values.</returns>
        public override string ToString()
        {
            return Synergist.Utility.GetProperties(this);
        }
    }
}
